package com.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.entity.Department;

public class DepartmentCtrl {
	public ArrayList<Department> getDepartment(){
		ArrayList<Department> acata = null;
		Connection conn = ConnDB.getConn();
		Statement stmt = null;
		ResultSet rs = null;
		String sql = "select depart_id,depart_name from department";
		try {
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				if (acata == null) {
					acata = new ArrayList<Department>();
				}
				Department department = new Department();
				department.setDepart_id(rs.getInt("depart_id"));
				department.setDepart_name(rs.getString("depart_name"));
						
				acata.add(department);
			}
			return acata;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			ConnDB.close(rs, stmt, conn);
		}
		return acata;
	}

}
